package com.example.lzy.lzydemo;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;

public class PropertyActivity extends AppCompatActivity {
    private ImageView img;
    private Button btnstart;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_property);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        img=(ImageView)findViewById(R.id.tweenImageView);
        btnstart=(Button)findViewById(R.id.btnStart);
        btnstart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //方法一
//                ObjectAnimator.ofFloat(img, "rotation",0.0f,360f).setDuration(3000).start();
//                ObjectAnimator.ofFloat(img,"translationX",0f,200f).setDuration(3000).start();
//                ObjectAnimator.ofFloat(img,"translationY",0f,200f).setDuration(3000).start();

                //方法二
//                PropertyValuesHolder p1 = PropertyValuesHolder.ofFloat("rotation",0.0f,360f);
//                PropertyValuesHolder p2 = PropertyValuesHolder.ofFloat("translationX",0.0f,200f);
//                PropertyValuesHolder p3 = PropertyValuesHolder.ofFloat("translationY",0.0f,200f);
//                ObjectAnimator.ofPropertyValuesHolder(img, p1,p2,p3).setDuration(1000).start();

                //方法三
                AnimatorSet set = new AnimatorSet();
                ObjectAnimator anim1= ObjectAnimator.ofFloat(img, "rotation",0.0f,360f);
                ObjectAnimator anim2= ObjectAnimator.ofFloat(img,"translationX",0f,200f);
                ObjectAnimator anim3= ObjectAnimator.ofFloat(img,"translationY",0f,200f);
                set.play(anim2).after(anim3);
                set.play(anim1);

                set.setDuration(3000);
                set.start();

            }
        });
        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
    }

}
